package avicit.bdp.dgs.qa.rest;

import avicit.bdp.dgs.qa.service.MetricService;
import avicit.platform6.core.rest.msg.ResponseMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @金航数码科技有限责任公司
 * @作者：developer
 * @邮箱：developer@avic-digital.com
 * @创建时间： 2023-06-14
 * @类说明：MetricRest
 * @修改记录：
 * @注意事项：
 * @主要功能：质量概览Rest接口
 */
@RestController
@Api(tags = "qa", description = "质量概览Rest接口")
@RequestMapping("/api/bdp/dgs/qa/metric")
public class MetricRest {
    @Autowired
    private MetricService metricService;

    /**
     * 查看基本指标，包括模板总数、规则总数、任务总数、评估次数、告警次数
     *
     * @return
     */
    @GetMapping("/queryBasicMetrics")
    @ApiOperation(value = "查看基本指标，包括模板总数、规则总数、任务总数、评估次数、告警次数")
    public ResponseMsg<Map<String, Object>> queryBasicMetrics() {
        ResponseMsg<Map<String, Object>> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.metricService.queryBasicMetrics(null, null));

        return responseMsg;
    }

    /**
     * 查看质量评分趋势图
     *
     * @param timeMode,时间，0：近24h、1：近7天、2：近30天
     * @return
     */
    @GetMapping("/queryScoreTrend")
    @ApiOperation(value = "查看质量评分趋势图")
    public ResponseMsg<List<Map<String, Object>>> queryScoreTrend(@ApiParam(value = "时间，0：近24h、1：近7天、2：近30天", name = "timeMode")
                                                                  @RequestParam(required = false, defaultValue = "0") Integer timeMode) {
        ResponseMsg<List<Map<String, Object>>> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.metricService.queryScoreTrend(timeMode, null, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())));

        return responseMsg;
    }

    /**
     * 查看质量告警趋势图
     *
     * @param timeMode,时间，0：近24h、1：近7天、2：近30天
     * @return
     */
    @GetMapping("/queryAlertTrend")
    @ApiOperation(value = "查看质量告警趋势图")
    public ResponseMsg<List<Map<String, Object>>> queryAlertTrend(@ApiParam(value = "时间，0：近24h、1：近7天、2：近30天", name = "timeMode")
                                                                  @RequestParam(required = false, defaultValue = "0") Integer timeMode) {
        ResponseMsg<List<Map<String, Object>>> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.metricService.queryAlertTrend(timeMode, null, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())));

        return responseMsg;
    }

    /**
     * 查看质量评分分布图
     *
     * @return
     */
    @GetMapping("/queryScoreDistribution")
    @ApiOperation(value = "查看质量评分分布图")
    public ResponseMsg<List<Map<String, Object>>> queryScoreDistribution() {
        ResponseMsg<List<Map<String, Object>>> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.metricService.queryScoreDistribution(null, null));

        return responseMsg;
    }

    /**
     * 查看质量评分排名
     *
     * @param rankMode,排名方式，0：排名最高、1：排名最低"
     * @return
     */
    @GetMapping("/queryScoreRank")
    @ApiOperation(value = "查看质量评分排名")
    public ResponseMsg<List<Map<String, Object>>> queryScoreRank(@ApiParam(value = "排名方式，0：排名最高、1：排名最低", name = "rankMode")
                                                                 @RequestParam(required = false, defaultValue = "0") Integer rankMode,
                                                                 @ApiParam(value = "排名总数，默认10", name = "limitNum")
                                                                 @RequestParam(required = false, defaultValue = "10") Integer limitNum) {
        ResponseMsg<List<Map<String, Object>>> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.metricService.queryScoreRank(rankMode, limitNum, null, null));

        return responseMsg;
    }
}
